<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<%@ include file="/WEB-INF/common/public.jspf"%>
		<%@ include file="/WEB-INF/common/easyui.jspf"%>

		<title>供应商列表</title>
	</head>

	<body>
		<script type="text/javascript">
			$(function() {
				$('#supplierList').datagrid({
					url: '${baseUrl}/supplier/getPage',
					pagination: true,
					fitColumns: true,
					method:"post",
					striped: true,
					idField: 'supId',
					loadMsg: '正在加载数据,请稍等.',
					rownumbers: true,
					fit: true,
					remoteSort: false,
					columns: [
						[{
							checkbox: true
						}, {
							field: 'supId',
							title: 'supId',
							sortable: true,
							width: 300,
							hidden: true
						}, {
							field: 'supName',
							title: '提供商',

							sortable: true,
							width: 300,

						}, {
							field: 'supLinkman',
							title: '联系人',
							sortable: true,
							width: 300
						}, {
							field: 'supPhone',
							title: '联系电话',
							width: 300,
							sortable: true
						}, {
							field: 'supAddress',
							title: '公司地址',
							width: 300,
							sortable: true
						}, {
							field: 'supRemark',
							title: '备注',
							width: 300,
							sortable: true
						}]
					],
					 toolbar: [ {
							text: '刷新',
							iconCls:'icon-reload',
							handler:function (){
								$('#supplierList').datagrid("reload");
								$('#supplierList').datagrid("clearSelections");
								$("#s_supName").val('搜索提供商');
								$("#s_supLinkMan").val("搜索联系人");
							}
						}, '-',
						{
							text:'添加',
							iconCls:'icon-add',
							handler:function (){
						
								parent.$("#win").dialog({
									title:'添加',
									width:400,
									height:300,
								    modal:true,
								    collapsible:false,
								    content:"<iframe src='${baseUrl}/supplier/addSupplier'  title='添加供应商' height='100%' width='100%' frameborder='0' ></iframe>"
								   /*  buttons:[{
										text:'提交',
										handler:function(){
											alert("submit");
											var v=parent.$("#win").children("[title='添加供应商']");
											
											
										}
									},{
										text:'重置',
										handler:function(){}
									}] */


								})
								

							}
						},'-',{
						iconCls: 'icon-remove',
						text: '删除',
						handler:function(){
							
							var selections = $('#supplierList').datagrid("getSelections");
							if(selections.length == 0) {
								parent.$.messager.alert('警告', '请选择删除行', 'warning');
								return false;
							}
							var pids = new Array();
							for(var i=0;i<selections.length;i++){
								pids[i]=selections[i].supId;
							}
							
							
							$.ajax({
								type:"post",
								traditional:true,
								url: "${baseUrl}/supplier/deleteList",
								async:true,
								data:{pids:pids},
								success: function(data) {
									if(data==0){
										$.messager.alert("提示","删除失败,请与管理员联系","warning");
										return ;
									}
									
									
									reload("delete");
									$('#supplierList').datagrid("clearSelections");
									$.messager.alert("提示","删除成功","info");
									
								}
							});
							
						}
						
						
					}, '-', {
						text: '<input type="text" id="s_supName" value="搜索提供商" />'
					},'-', {
						text: '<input type="text" id="s_supLinkMan" value="搜索联系人" />'
						
					},'-', {
						iconCls: 'icon-search',
						id:'search_bnt',
						handler:function (){
							reload("search");
						}
					},'-', {
						iconCls: 'icon-help',
						text: '帮助',
						handler: function() {
							alert('帮助按钮');
						}
					}]
 
				});
				
				$("input[id^='s_sup']").focusin(function (){
					
					
					$(this).val("");
				});
				
				function reload(param){
					var v1  =$("#s_supName").val();
					var v2	=$("#s_supLinkMan").val();
					if(param == 'search' && ((v1 == '搜索提供商' || v1=='') && (v2 =='搜索联系人' || v2=='') )  ){
						$.messager.alert("警告提示","请输入搜索条件","warning");
						return ;
					}
					
					if(v1 != '搜索提供商'){
						v1='%'+v1+'%';
					}else{
						v1='';
					}
					if(v2 !="搜索联系人"){
						v2='%'+v2+'%';
					}else{
						v2='';
					}
					var dg=$('#supplierList').datagrid("options");
					var rows=dg.pageSize;
					
					$.ajax({
						type:"post",
						traditional:true,
						url: "${baseUrl}/supplier/getPageByExample",
						async:true,
						data:{supName:v1,supLinkman:v2,rows:rows},
						success: function(data) {

							$('#supplierList').datagrid("loadData",data);
		
						}
					});
					
				}

			})
		</script>
		<table id="supplierList"></table>
		
	</body>

</html>